package example

import grails.gorm.multitenancy.Tenant
import grails.gorm.multitenancy.Tenants
import grails.gorm.multitenancy.WithoutTenant
import grails.test.mongodb.MongoSpec
import grails.testing.gorm.DomainUnitTest
import org.grails.datastore.mapping.mongo.MongoDatastore
import org.grails.datastore.mapping.multitenancy.resolvers.SystemPropertyTenantResolver

class PersonSpec extends MongoSpec implements DomainUnitTest<Person> {

    def setup() {
    }

    def cleanup() {
    }

    @WithoutTenant(datastore = MongoDatastore)
    void "test save without tenant"() {
        when:
        new Person(name: "mars", gender: 1).save()

        then:
        Tenants.currentId(MongoDatastore) == "DEFAULT"
        Person.count == 1
    }

    @Tenant(value = { "tenant1" }, datastore = MongoDatastore)
    void "test save in tenant1"() {
        when:
        new Person(name: "mars", gender: 1).save()

        then:
        Tenants.currentId(MongoDatastore) == "tenant1"
        Person.count == 1
    }
}
